
package cn.pconline.autoclub.entity;

import cn.pconline.autoclub.util.StringUtil;
import cn.pconline.autoclub.util.WebUtils;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.gelivable.dao.Column;
import org.gelivable.dao.Entity;
import org.gelivable.dao.Transient;

/**
 *
 * @author ppc
 */
@Entity(tableName = "ac_comment", split="Mod:clubId:10")
public class Comment {
    public final static int STATUS_NORMAL = 1;  // 正常状态
    public final static int STATUS_DELETE = -1; // 已删除状态
    public final static int CENSORED_NORMAL = 1; // 审核通过
    public final static int CENSORED_DELETE = -1; //审核未通过
    public final static int CENSORED_NOCAREFUL = 0 ; //未审状态
    public final static String TABLE_NAME="ac_comment";
    @Column(name = "comment_id")
    private long commentId; //留言ID
    @Column(name = "club_id")
    private long clubId; //车友会ID
    @Column(name = "comment_content")
    private String content; //留言内容
    @Column(name = "create_by")
    private long createBy; //发言人
    @Column(name = "status")
    private int status; //状态 1:正常状态 -1:删除状态
    @Column(name = "is_pic")
    private int isPic; // 是否有图片
    @Column(name = "create_at")
    private Date createDate; // 发言时间
    @Column(name = "update_at")
    private Date updateDate; //最后修改时间
    @Column(name = "reply_num")
    private int replyNum; //回复数
    @Column(name = "main_comment_id")
    private long replyId; //回复留言ID
    @Column(name = "img_url1")
    private String imgUrl1; //图片地址1
    @Column(name = "img_url2")
    private String imgUrl2; //图片地址2
    @Column(name = "censored") 
    private int censored; //审核状态：0未审，1：审核通过 -1：审核未通过
    @Transient(cache=false)
    private User user;//发言人
    @Transient(cache=false)
    private String imgUrl;//用户头像
    
    @Transient(cache=false)
    private String imgUrl1x700;
    @Transient
    private String imgUrl2x700;
    @Transient(cache=false)
    private String imgUrl1x240;
    @Transient
    private String imgUrl2x240;
	@Transient(cache=false)
    private List<Comment> replys;
	
	public String getImgUrl1x700() {
		return convertSize(imgUrl1,"_240","_700");
	}

	public String getImgUrl2x700() {
		return convertSize(imgUrl2,"_240","_700");
	}
	
	
	public String getImgUrl1x240() {
		return convertSize(imgUrl1,"_240","_240x240");
	}

	public String getImgUrl2x240() {
		return convertSize(imgUrl2,"_240","_240x240");
	}

	public String convertSize(String url,String oldSize,String newSize){
		if(StringUtils.isBlank(url)){
			return "";
		}
		return url.replace(oldSize, newSize);
	}
	
    public long getCommentId() {
        return commentId;
    }

    public long getClubId() {
        return clubId;
    }


    public int getStatus() {
        return status;
    }

    public int getIsPic() {
        return isPic;
    }

    public Date getCreateDate() {

        return createDate;
    }

    public Date getUpdateDate() {
        return updateDate;
    }

    public int getReplyNum() {
        return replyNum;
    }

    public long getCreateBy() {
        return createBy;
    }

    public long getReplyId() {
        return replyId;
    }

    public String getContent() {
        if(content!=null){
            return StringUtil.filterBack(content.replaceAll("<", "&lt;")
                .replaceAll(">", "&gt;")
                .replaceAll("'", "&apos;")
                .replaceAll("\"", "&quot;"));
        }
        return content;
    }

    public String getAppContent(){
    	if(content!=null){
    		return StringUtil.backBr(content.replaceAll("&lt;", "<")
                    .replaceAll("&gt;", ">")
                    .replaceAll("&apos;", "'")
                    .replaceAll("&quot;", "\""));
    	}
    	return content;
    }

    public String getImgUrl1() {
        if(imgUrl1!=null) {
            return imgUrl1.replaceAll("<", "&lt;")
                .replaceAll(">", "&gt;")
                .replaceAll("'", "&apos;")
                .replaceAll("\"", "&quot;");
        }
        return imgUrl1;
    }

    public String getImgUrl2() {
        if(imgUrl2!=null) {
            return imgUrl2.replaceAll("<", "&lt;")
                .replaceAll(">", "&gt;")
                .replaceAll("'", "&apos;")
                .replaceAll("\"", "&quot;");
        }
        return imgUrl2;
    }

    public int getCensored() {
        return censored;
    }

    public void setCensored(int censored) {
        this.censored = censored;
    }

  
    public String getImgUrl(){
       return  WebUtils.face(createBy, 50);
    }
    public String getUserName(){
        if(user!=null){
            return user.getNickname();
        }
        return "";
    }
    public User getUser(){
        return user;
    }
    public void setUser(User user){
        this.user=user;
    }
    public void setCommentId(long id) {
        this.commentId = id;
    }

    public void setClubId(long clubId) {
        this.clubId = clubId;
    }

    public void setCreateBy(long createBy) {
        this.createBy = createBy;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setIsPic(int isPic) {
        this.isPic = isPic;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public void setReplyNum(int replyNum) {
        this.replyNum = replyNum;
    }

    public void setReplyId(long replyId) {
        this.replyId = replyId;
    }

    public void setImgUrl1(String imgUrl1) {
        this.imgUrl1 = imgUrl1;
    }

    public void setImgUrl2(String imgUrl2) {
        this.imgUrl2 = imgUrl2;
    }

    public List<Comment> getReplys() {
        return replys;
    }

    public void setReplys(List<Comment> replys) {
        this.replys = replys;
    }
}
